package com.gqmk.demo.springcloudconsumer.controller;

import com.gqmk.demo.springcloudapi.domain.Demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/consumer")
public class ConsumerController {

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("demo")
    public Demo getDemo(){
        // 直接调用服务器接口服务
//        return restTemplate.getForObject("http://localhost:8081/provider/demo", Demo.class);

        // 通过 Eureka 微服务提供者 方式访问
        return restTemplate.getForObject("http://DEMO-PROVIDER/provider/demo", Demo.class);
    }
}
